package ${package.ServiceImpl};

import ${package.Entity}.${entity};
import ${package.Mapper}.${table.mapperName};
import ${package.Service}.${table.serviceName};
import ${superServiceImplClassPackage};
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.List;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

/**
* <p>
* ${table.comment!} 服务实现类
* </p>
*
* @author ${author}
* @since ${date}
*/
@Slf4j
@Service
public class ${table.serviceImplName} extends ${superServiceImplClass}<${table.mapperName}, ${entity}> implements ${table.serviceName} {

    @Override
    public void add(${entity} entity) {
        baseMapper.insert(entity);
    }

    @Override
    public void updById(${entity} entity) {
        baseMapper.updateById(entity);
    }

<#-- 遍历字段列表以找到主键 -->
<#list table.fields as field>
<#if field.keyFlag>
    @Override
    public void delByIds(List<${field.propertyType}> ids) {
        baseMapper.deleteBatchIds(ids);
    }

    @Override
    public ${entity} getDetail(${field.propertyType} id) {
        return baseMapper.selectById(id);
    }
    <#break>
</#if>
</#list>

    @Override
    public IPage<${entity}> getPage(Long pageNum, Long pageSize) {
        if (pageNum == null || pageNum <= 0) { pageNum = 1L; }
        if (pageSize == null || pageSize <= 0) { pageSize = 10L; }
        IPage<${entity}> page = new Page<>(pageNum, pageSize);
        Wrapper<${entity}> wrapper = new LambdaQueryWrapper<${entity}>();
        return baseMapper.selectPage(page, wrapper);
    }

}
